﻿using System;
using Loki.Model;
using Luna.Data.Budget;

namespace Luna.Model.Budget
{
    public class LunaBudgetService : LunaService, IBudgetService
    {
        private EntityContainer<IBudget, Guid> budgets;

        private EntityContainer<ICategory, Guid> categories;

        public LunaBudgetService()
        {
            categories = CreateContainer<ICategory, Guid>(CacheConfiguration.CATEGORIES);
            budgets = CreateContainer<IBudget, Guid>(CacheConfiguration.BUDGET);
        }

        public IIndexedEnumerable<IBudget, Guid> Budgets
        {
            get { return budgets; }
        }

        public IIndexedEnumerable<ICategory, Guid> Categories
        {
            get { return categories; }
        }

        public void Delete(IEditableCategory P_Category)
        {
            Delete<Category, ICategory, IEditableCategory, ICategoryData>(P_Category, DataResolver.Get<IBudgetProvider>().CategoryDelete, categories);
        }

        public void Delete(IEditableBudget P_Budget)
        {
            Delete<EditableBudget, IBudget, IEditableBudget, IBudgetData>(P_Budget, DataResolver.Get<IBudgetProvider>().BudgetDelete, budgets);
        }

        public void Reset()
        {
            categories.Reset();
            budgets.Reset();
        }

        public void Save(IEditableCategory P_Category)
        {
            Save<Category, ICategory, IEditableCategory, ICategoryData>(P_Category, DataResolver.Get<IBudgetProvider>().CategorySave, categories);
        }

        public void Save(IEditableBudget P_Budget)
        {
            Save<EditableBudget, IBudget, IEditableBudget, IBudgetData>(P_Budget, DataResolver.Get<IBudgetProvider>().BudgetSave, budgets);
        }
    }
}